package com.edu.boot.config;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateSerializer extends StdSerializer<Date> {
    
    private static final SimpleDateFormat formatter = new SimpleDateFormat(Constants.DATE_TIME_FORMAT);
    
    public DateSerializer() {
        this(null);
    }
    
    public DateSerializer(Class<Date> t) {
        super(t);
    }
    
    @Override
    public void serialize(Date value, JsonGenerator gen, SerializerProvider provider) throws IOException {
        gen.writeString(formatter.format(value));
    }
}
